package com.bookRecommend.service.impl;

import com.bookRecommend.mapper.ICommentMapper;
import com.bookRecommend.model.Comment;
import com.bookRecommend.service.ICommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentServiceImpl implements ICommentService {

    @Autowired
    ICommentMapper mapper;

    @Override
    public PageInfo<Comment> findPage(Integer pageNum, Integer size) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (size == null) {
            size = 5;
        }
        PageHelper.startPage(pageNum, size);
        return new PageInfo<>(mapper.selectComments());
    }

    @Override
    public int removeById(Integer id) {
        if (id == null) {
            return 0;
        }
        return mapper.deleteById(id);
    }
}
